// index.js
// 获取应用实例
const app = getApp()
import { getStorage } from '../../common/utils'

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,

    item_data: {
      title: '健康管理师教材5册装健康管理师教材5册装5册装',
      price: '2000.00'
    }
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: async function(option) {
    const scene = decodeURIComponent(option.scene);
    
    if(scene && scene != 'undefined') {
      wx.navigateTo({
        url: '/pages/orderInfo/index?scene=' + scene
      })
    }

    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  toPrice: async function(evt) {
    let token = await getStorage('user_info');
    if(token) {
      let { data } = evt.currentTarget.dataset;
      wx.navigateTo({url: '/pages/orderInfo/index?data=' + JSON.stringify(data)})
    }else{
      wx.showModal({
        title: '温馨提示',
        content: '请先进行登录',
        showCancel: false,
        confirmText: '去登录',
        success() {
          wx.navigateTo({url: '/pages/login/index'})
        }
      })
    }
  }
})
